<?php

/**
 * This is the model class for table "{{link}}".
 *
 * The followings are the available columns in table '{{link}}':
 * @property integer $link_id
 * @property integer $user_id
 * @property string $link_url
 * @property string $site_name
 * @property string $site_keyword
 * @property string $site_desc
 * @property string $type
 * @property string $post_time
 *
 * The followings are the available model relations:
 */
class Link extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Link the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{link}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_id, link_url, site_name, post_time', 'required'),
			array('user_id', 'numerical', 'integerOnly'=>true),
			array('link_url, site_name, site_keyword, post_time', 'length', 'max'=>255),
			array('type', 'length', 'max'=>5),
			array('site_desc', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('link_id, user_id, link_url, site_name, site_keyword, site_desc, type, post_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'link_id' => 'Link',
			'user_id' => 'User',
			'link_url' => 'Link Url',
			'site_name' => 'Site Name',
			'site_keyword' => 'Site Keyword',
			'site_desc' => 'Site Desc',
			'type' => 'Type',
			'post_time' => 'Post Time',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('link_id',$this->link_id);
		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('link_url',$this->link_url,true);
		$criteria->compare('site_name',$this->site_name,true);
		$criteria->compare('site_keyword',$this->site_keyword,true);
		$criteria->compare('site_desc',$this->site_desc,true);
		$criteria->compare('type',$this->type,true);
		$criteria->compare('post_time',$this->post_time,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}